﻿$(function()
{	
	var createPage = function(name, title, linkText, linkTarget)
	{			
		var button = $("<a></a>").addClass("button");
		
		if(typeof linkText == "undefined")
		{
			button.text("Back");
			button.addClass("back");
			button.attr("href", "#");			
		}
		else
		{
			button.text(linkText);
			button.attr("href", "#" + linkTarget)
		}
		
		var toolbar = $("<div></div>")
			.addClass("toolbar")
			.append(button)
			.append($("<h1></h1>").text(title));	
		
		var page = $("<div></div>")
			.attr("id", name)
			.append(toolbar);
		
		$(document.body).append(page);
		return page;
	};
	
	var createGameList = function(n)
	{
		var ul = $("<ul></ul>").addClass("rounded");
		for(var i=0; i<n; i++)
		{		
			var li = $("<li></li>").addClass("arrow");		
			var a = $("<a href=#question></a>").text("cyberfish");
			var small = $("<div></div>").addClass("small").text("Epistemology started 1/1/2011");
			a.append(small);			
			li.append(a);
			ul.append(li);			
		}
		
		return ul;
	};
	
	var createQuestion = function(question, options)
	{				
		var label = $("<div></div>")
			.addClass("question-text")
			.text(question);
		
		var question = $("<div></div>")
			.addClass("question")
			.attr("id", 1)
			.append(label);
		
		for(var i=0; i<options.length; i++)
		{
			question.append($("<div></div>")
				.addClass("button gray answer")
				.text(options[i]));
		}
				
		return question;
	};
	
	var createSeparator = function(str)
	{
		return $("<h2></h2>").text(str);
	};
			
	var question = createPage("question", "Question #1");
	question.append(createQuestion(
		"Vad hette Jane Austen egentligen?",
		["Carl Bildt", "Tio små negerpojkar", "Astrid", "Lasse-Maja"]));
			
	var invite = createPage("invite", "Create new game");	
	var settings = createPage("settings", "Settings");	
	
	var home = createPage("home", "Knudo", "Settings", "settings").addClass("current");	
	home.append(createSeparator("Current games"));		
	home.append(createGameList(5));
	home.append(createSeparator("Finished games"));
	home.append(createGameList(2));	
	
	var jQT = $.jQTouch({
		"icon" : "icon.png",
		"startupScreen" : "startup.png"
	});
});